<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>The &lt;plugin&gt; Element</title>
  <link type="text/css" rel="stylesheet" href="../style.css"/>
</head>
<body>

<div class="menuNav">
  <p>
    <a href="../index.html" target="_top">Show Menu</a>
    <a href="plugin.html" target="_top">Hide Menu</a>
  </p>
</div>

<h1>The &lt;plugin&gt; Element</h1>
<p>The &lt;plugin&gt; element is used to define a plugin.  Plugins can be used
to extend or modify the code generated by MyBatis Generator (MBG).    This element is a child element of the
<a href="context.html">&lt;context&gt;</a> element.  Any number of
plugins may be specified in a context.  The plugins will be called in
the order that are listed in the configuration.</p>

<p>For more information about plugins, see the
<a href="../reference/pluggingIn.html">Implementing MyBatis Generator Plugins</a> reference
page.</p>

<h2>Supplied Plugins</h2>
<p>MBG supplies several plugins (all are in the package
<code>org.mybatis.generator.plugins</code>).  The supplied plugins demonstrate
different types of tasks that can be accomplished with MBG plugins.  Source
code for the plugins is available with the MBG downloads, or can be viewed
online
<a target="_blank" href="http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/core/mybatis-generator-core/src/main/java/org/mybatis/generator/plugins/">
here</a>.</p>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Plugin</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top"><code>(package).CaseInsensitiveLikePlugin</code></td>
    <td>This plugin adds methods to the Example class (actually to the Criteria inner class)
        to support case insensitive LIKE searches.  This demonstrates adding functionality to
        the example classes via a plugin, rather than extending the class.</td>
  </tr>
  <tr>
    <td valign="top"><code>(package).EqualsHashCodePlugin</code></td>
    <td>This plugin adds <code>equals</code> and <code>hashCode</code> methods to the
        Java model objects generated by MBG.
        <p>The <code>equals</code> method generated by this class is correct in most
           cases, but will probably NOT be correct if you have specified a rootClass -
           because our equals method only checks the fields it knows about.</p>
        <p>The <code>hashCode</code> method generated by this class is a very simplistic
           implementation.  A better implementation would rely on the HashCodeUtil
           from <a target="_blank" href="http://www.javapractices.com">www.javapractices.com</a>
           - but we do not want to introduce another
           dependency in this simple plugin.</p></td>
  </tr>
  <tr>
    <td valign="top"><code>(package).MapperConfigPlugin</code></td>
    <td>This plugin generates a skeleton MapperConfig.xml file that contains
        references to the XML mapper files generated by MBG.
        This file can be used to configure MyBatis 3.x environments.
        <p>This plugin accepts three properties:</p>
        <ul>
          <li><tt>fileName</tt> (optional) the name of the generated file.
              this defaults to "MapperConfig.xml" if not specified.</li>
          <li><tt>targetPackage</tt> (required) the name of the package where the
              file should be placed.  Specified like "com.mycompany.sql".</li>
          <li><tt>targetProject</tt> (required) the name of the project where the
              file should be placed.</li>
        </ul>
        <p>Note: <code>targetPackage</code> and <code>targetProject</code> follow
           the same rules as the <code>targetPackage</code> and <code>targetProject</code>
           values on the sqlMapGenerator configuration element.</p></td>
  </tr>
  <tr>
    <td valign="top"><code>(package).RenameExampleClassPlugin</code></td>
    <td>This plugin demonstrates usage of the <code>initialized</code> method
        by renaming the generated example classes generated by MBG.
        <p>This plugin accepts two properties:</p>
        <ul>
          <li><tt>searchString</tt> (required) a regular expression used to search
              the default generated name of the example class.</li>
          <li><tt>replaceString</tt> (required) the string to be inserted on matches of the
            <tt>searchString</tt>.</li>
        </ul>
        <p>For example, to rename the generated example classes from xxxExample to
           xxxCriteria, specify <tt>Example$</tt> for <tt>searchString</tt>
           and <tt>Criteria</tt> for <tt>replaceString</tt></p></td>
  </tr>
  <tr>
    <td valign="top"><code>(package).SerializablePlugin</code></td>
    <td>This plugin adds the marker interface <code>java.io.Serializable</code> to the
        Java model objects generated by MBG.  This plugin also adds the
        <code>serialVersionUID</code> field to the model classes.
        <p>Important: This is a simplistic implementation of java.io.Serializable and does
           not attempt to do any versioning of classes.</p></td>
  </tr>
  <tr>
    <td valign="top"><code>(package).SqlMapConfigPlugin</code></td>
    <td>This plugin generates a skeleton SqlMapConfig.xml file that contains
        references to the SqlMap.xml files generated by MBG.
        This file can be used to configure iBATIS 2.x environments.
        <p>This plugin accepts three properties:</p>
        <ul>
          <li><tt>fileName</tt> (optional) the name of the generated file.
              this defaults to "SqlMapConfig.xml" if not specified.</li>
          <li><tt>targetPackage</tt> (required) the name of the package where the
              file should be placed.  Specified like "com.mycompany.sql".</li>
          <li><tt>targetProject</tt> (required) the name of the project where the
              file should be placed.</li>
        </ul>
        <p>Note: <code>targetPackage</code> and <code>targetProject</code> follow
           the same rules as the <code>targetPackage</code> and <code>targetProject</code>
           values on the sqlMapGenerator configuration element.</p></td>
  </tr>
</table>


<h2>Required Attributes</h2>
<table border="1" cellspacing="0" cellpadding="5">
  <tr>
    <th>Attribute</th>
    <th>Description</th>
  </tr>
  <tr>
    <td valign="top">type</td>
    <td>The fully qualified name of the class that implements the plugin.
        The class must implement the interface
        <code>org.mybatis.generator.api.Plugin</code>,
        and must have a public default constructor.  Note that it is far
        easier to extend the adapter class
        <code>org.mybatis.generator.api.PluginAdapter</code>
        than to implement the entire interface.</td>
  </tr>
</table>

<h2>Optional Attributes</h2>
<p>None</p>

<h2>Child Elements</h2>
<ul>
  <li><a href="property.html">&lt;property&gt;</a> (0 or 1)</li>
</ul>

</body>
</html>
